package com.wyw.learning.thread.threadpool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 缓存线程池
 *      特点：无界线程池，具有自动回收多余线程的功能
 *      maxPoolSize  Integer.MAX_VALUE，也会导致OOM情况的发生
 *  CachedThreadPool使用的Queue是SynchronousQueue
 *  cache体现在对线程的缓存，如果一段时间线程空闲，就会被回收
 *
 * @author Mr Wu    yewen.wu.china@gmail.com
 * @date 2021/7/4   5:45 下午
 * <p>
 * Update History:
 * Author        Time            Content
 */
public class CacheThreadPool {
    public static void main(String[] args) {
        ExecutorService executorService = Executors.newCachedThreadPool();
        for (int i = 0; i< 1000; i++){
            executorService.execute(new Task());
        }
    }
}
